#include "EffectManager.h"

#include "EffectListParser.h"
#include "EffectLoader.h"

EffectManager::EffectManager()
{ }

void EffectManager::loadEffects(const QString& listFilename)
{
	EffectListParser parser;
	parser.parse(listFilename);

	QMap<QString, QString> effectEntries = parser.effects();

	foreach(QString key, effectEntries.keys())
	{
		QString filename = effectEntries[key];
		
		EffectLoader loader;
		Effect effect = loader.load(filename);
		m_effects.push_back(effect);
	}
}

void EffectManager::setActiveEffect(const QString& name)
{
	m_activeEffect->deactivate();

	for(int i = 0; i < m_effects.size(); ++i)
	{
		Effect& e = m_effects[i];
		if(e.name() == name)
		{
			m_activeEffect = &e;
			m_activeEffect->activate(m_glContext);
		}
	}
}